var app = getApp();
var Api = require("../../../api/method.js");
Page({
  /**
   * 页面的初始数据
   */
  data: {
    Salesmanlist:"",
    arr:[],
    pop:true,
    qrUrl:"",
    nickName:"",
    user:""
  },
  //更多跳转
  more:function(e){
    wx.navigateTo({
      url:"/pages/branch/more/more",
    })
  },
  //业务员详情
  listdetails:function(e){
    let openid = e.currentTarget.dataset.openid;
    wx.navigateTo({
      url: "/pages/branch/detail/detail?openid=" + openid,
    })
  },
  //点击弹框
  logo: function (e) {
    this.setData({
      pop: false
    })
  },
  //搜索值
  getUsername: function (e) {
    this.setData({
      user: e.detail.value
    })
    if(this.data.user == ""){
      this.Salesmanlist();
    }
  },
  //概览搜索
  Search:function(e){
    let that = this;
    if(that.data.user == ""){
      wx.showToast({
        icon: "none",
        duration: 1500,
        title: "请输入搜索内容"
      })
      return
    }
    wx.showToast({
      title: '加载中',
      icon: 'loading'
    });
    // let list = {
    //   nickName:that.data.user
    // };
    // Api.searchSalesman(list, function (err, res) {
    //   console.log(res.data);
    //   if(res.data.code == 1){
    //     var Salesmanlist = [];
    //     Salesmanlist.push(res.data.data);
    //     that.setData({
    //       Salesmanlist: Salesmanlist
    //     });
    //     // console.log(that.data.Salesmanlist);
    //     wx.hideLoading();
    //   }
    // });
    let list = {
      pageNo: 1,
      branchId: wx.getStorageSync("user").branchId,
      pageSize: 20,
      nickName: that.data.user
    };
    console.log(list);
    Api.Salesmanlist(list, function (err, res) {
      if (res.data.code == 1) {
        that.setData({
          Salesmanlist: res.data.data
        });
        wx.hideLoading();
      }
    }); 
  },
  //隐藏白条弹框
  hideBaitiaoView: function (e) {
    if (e.target.dataset.target == 'self')
      this.setData({
        pop: true
      })
  },
  //业务总览
  general:function(){
    wx.navigateTo({
      url: "/pages/branch/Orderdetails/Orderdetails",
    })
  },
  //分院概览
  branchgailan:function(){
    wx.showToast({
      title: '加载中',
      icon: 'loading'
    });
    let that = this;
    let list = {
      branchId: wx.getStorageSync("user").branchId
    }
    Api.branch(list, function (err, res) {
      console.log(res.data)
      if (res.data.code == 0) {
        wx.showToast({
          title: '登录失败',
          icon: 'fail',
          duration: 2000
        })
      } else {
        var Arr = res.data.data;
        Arr.grossIncome % 100;
        var grossIncome = Arr.grossIncome / 100;
        that.data.arr.push(Arr);
        that.setData({
          arr: that.data.arr,
          grossIncome:grossIncome
        })
      }
      wx.hideToast();
    })
  },
  //业务员列表
  Salesmanlist:function(){
    let that = this;
    let list = {
      pageNo:1,
      branchId:wx.getStorageSync("user").branchId,
      pageSize:20
    };
    console.log(list);
    Api.Salesmanlist(list, function (err, res) {
      // console.log(res.data);
      if (res.data.code == 1) {
        that.setData({
          Salesmanlist:res.data.data
        })
      }
    }); 
  },
  //退出登录
  goout: function () {
    wx.clearStorage();
    wx.navigateTo({
      url: '/pages/Portalpage/Portalpage',
    })
  },
  //点击图片二维码
  dada: function (e) {
    console.log(e)
    var img = [];
    img.push(e.currentTarget.dataset.src);
    wx.previewImage({
      current: e.currentTarget.dataset.src,
      urls: img
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.Salesmanlist();
    this.branchgailan();
    this.setData({
      qrUrl: wx.getStorageSync("user").qrUrl,
      nickName:wx.getStorageSync("user").nickName
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    //加载本页面的tabBar样式
    app.editTabBar1();
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})